<template>
  <div class="login-wrapper">
    <div class="login-container">
      <div>
        <div class="form-group">
          <label for="username">用户名</label>
          <input type="text" id="username" v-model="username"/>
        </div>
        <div class="form-group">
          <label for="password">密码</label>
          <input type="password" id="password" v-model="password"/>
        </div>
        <button @click="login">登录</button>
      </div>
      <p v-if="errorMessage" class="error-message">{{ errorMessage }}</p>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

var router = useRouter()
var username = ref()
var password = ref()
var errorMessage = ref()

// 实现登录功能，如果后端实现此处路由时向下一个页面传递用户id信息
function login() {
  if (username.value == 'sanmao' && password.value == '123456') {
    router.push({
      path: '/home',
    //query: {}
    })
  }else{
    errorMessage.value = '请输入sanmao和123456'
  }
}
</script>

<style lang="scss" scoped>
.login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f5f5;
}

.login-container {
  max-width: 400px;
  width: 100%;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  background-color: #fff;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
}

.form-group input {
  width: 100%;
  padding: 8px;
  box-sizing: border-box;
}

button {
  width: 100%;
  padding: 10px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}

.error-message {
  color: red;
  margin-top: 10px;
}
</style>
